home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
drdobbs
/
c_spec
/
execute
/
date.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-02-20
|
3KB
|
126 lines
#include <stdio.h>
#include "/include/mydos.h"
#undef min
/* DATE.C Get the date from dos
*
* Copyright (C) 1986, Allen I. Holub. All rights reserved.
*/
#define E(x) fprintf(stderr,"%s\n", x );
extern void mydos( REGS * ); /* In mydos.asm */
extern void gregs( REGS * );
/*----------------------------------------------------------------------*/
static char *weekdays[] =
{
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
};
static char *months[] =
{
"", /* There is no month 0 */
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
/*----------------------------------------------------------------------*/
date( month, day, year, day_of_the_week )
int *month, *day, *year, *day_of_the_week ;
{
/* Return the month, day, year, and day of the week (0 = sunday,
* 6 = saturday). This function is totally non-portable,
* and must be compiled with the lattice C compiler.
*/
REGS regs;
gregs(®s);
regs.h.ah = 0x2a ;
mydos( ®s );
*month = regs.h.dh ;
*day = regs.h.dl ;
*year = regs.x.cx ;
*day_of_the_week = regs.h.al ;
}
/*----------------------------------------------------------------------*/
time( hr, min, sec, hundredths )
int *hr, *min, *sec, *hundredths;
{
/* Return the time. This is probably non-portable
*/
REGS regs ;
gregs( ®s );
regs.h.ah = 0x2c ;
mydos( ®s );
*hr = regs.h.ch ;
*min = regs.h.cl ;
*sec = regs.h.dh ;
*hundredths = regs.h.dl ;
}
/*----------------------------------------------------------------------*/
#ifdef DEBUG
main()
{
int hr, min, sec, hundredths;
time( &hr, &min, &sec, &hundredths );
printf("time is %d:%d:%d.%d\n", hr, min, sec, hundredths );
}
#endif
/*----------------------------------------------------------------------*/
main(argc, argv)
char **argv;
{
static int hr, min, sec, hund, mo, day, yr, dow ;
time( &hr, &min, &sec, &hund );
date( &mo, &day, &yr, &dow );
if( argc <= 1 )
printf("%s. %s %02d, %d %02d:%02d:%02d\n",
weekdays[dow], months[mo], day, yr, hr, min, sec);
else if( argv[1][0] == '-' && argv[1][1] == 'n' )
printf("%02d/%02d/%02d %02d:%02d:%02d\n",
yr, mo, day, hr, min, sec);
else
{
E("Date: Copyright (c) 1986, Allen I. Holub. All rights reserved.");
E("\nUsage: date [-n]\n");
E("Print the date and time in English by default, in numeric");
E("format (YY:MM:DD HH:MM:SS) if -n is given on command line.");
}
}